package com.wwz.activiti;

import com.wwz.activiti.pojo.Holiday;
import org.activiti.engine.*;
import org.activiti.engine.repository.Deployment;
import org.activiti.engine.runtime.ProcessInstance;
import org.activiti.engine.task.Task;

import java.util.HashMap;
import java.util.Map;

/**
 * @Description: 流程变量测试：通过流程id 设置全局变量
 * @create: 2021-04-08 14:04:40
 * @author:wwz
 */
public class VariableTest3 {
    public static void main(String[] args) {
//        //1.流程部署
//        ProcessEngine processEngine = ProcessEngines.getDefaultProcessEngine();
//        //1.1 得到repositoryService
//        RepositoryService repositoryService = processEngine.getRepositoryService();
//
//        //1.2部署
//        Deployment deploy = repositoryService.createDeployment()
//                .addClasspathResource("diagram/holiday4.bpmn")
//                .addClasspathResource("diagram/holiday4.png")
//                .name("请假流程3-流程变量")
//                .deploy();
//
//        System.out.println(deploy.getId());
//        System.out.println(deploy.getName());


        //=================================================

        //1.启动流程实例
        ProcessEngine processEngine = ProcessEngines.getDefaultProcessEngine();
        //1.1得到runtimeService
        RuntimeService runtimeService = processEngine.getRuntimeService();
        //流程定义的key myProcess_1
        String key = "myProcess_1";
        //Map<String, Object> map = new HashMap<String, Object>();
        Holiday holiday = new Holiday();
        holiday.setNum(5F);
        //map.put("holiday",holiday);
        //1.2
        //启动流程实例并且设置流程变量的值
        //影响表ACT_GE_BYTEARRAY   ACT_RU_VARIABLE
        //通过实例id，设置流程变量
        // 1 流程实例的id  2 流程变量名 3 value
        runtimeService.setVariable("2501","holiday",holiday);
        //一次设置多个值。
        //runtimeService.setVariables("2501",variables);



        //=================================================

        //完成任务
//        ProcessEngine processEngine = ProcessEngines.getDefaultProcessEngine();
//
//        TaskService taskService = processEngine.getTaskService();
//
//        String key = "myProcess_1";
//        Map<String, Object> map = new HashMap<String, Object>();
//        Holiday holiday = new Holiday();
//        holiday.setNum(5F);
//        map.put("holiday",holiday);
//        Task task = taskService.createTaskQuery().processDefinitionKey(key).taskAssignee("zhangsan").singleResult();
//        if(task != null){
//            //完成任务时，设置流程变量，走不同审批流程。
//            taskService.complete(task.getId(),map);
//            System.out.println("任务执行完毕");
//        }



    }
}
